// pages/centerWallet/centerWallet.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userWallet:[],
    newmoney:'',
  },
  onLoad:function(){
    //获取用户id发送请求
    var userid = wx.getStorageSync("OoOoUserid");
    var data = {
      userid:userid,
    }
    var that = this;
    //获取个人资料信息
    wx.request({
      url:'http://47.104.142.216/TP/public/index.php/index/Usercenter/index_lwx',
      dataType:'json',
      method:'POST',
      data:data,
      header:{
        'content-type':'application/x-www-form-urlencoded'
      },
      success:function(res){
          that.setData({
            //第一个data为固定用法
            userWallet: res.data
          })
        },
        fail:function(err){
        console.log(err)
        }
    });
  },
  savemoneyBtn:function(e){
    var that = this;
    if(e.detail.value.newmoney == ''){
      wx.showToast({
        title: '请输入金额',
        icon: 'none',
        duration: 2000
      })
      return;
    }else if(e.detail.value.newmoney == 0){
      wx.showToast({
        title: '请输入正确金额',
        icon: 'none',
        duration: 2000
      })
      return;
    }else if(e.detail.value.newmoney >= 999999){
      wx.showToast({
        title: '单次充值金额最大范围 999999',
        icon: 'none',
        duration: 2000
      })
      return;
    }
    var userid = wx.getStorageSync("OoOoUserid");
    var newmoney = e.detail.value.newmoney;
    var data = {
      userid : userid,
      addmoney : newmoney, //新余额
    }
    //充值金额
    wx.request({
      url:'http://47.104.142.216/TP/public/index.php/index/Usercenter/rechargeMoney',
      dataType:'json',
      method:'POST',
      data:data,
      header:{
        'content-type':'application/x-www-form-urlencoded'
      },
      success:function(res){
          if(res.data == 10000){
            wx.showToast({
              title: '充值成功',
              icon: 'success',
              duration: 2000
            })

            that.onLoad()
            return;
          }
        },
        fail:function(err){
        console.log(err)
        }
    });

  }
})